//
//  HomeCollectionView.m
//  大轮胎
//
//  Created by 朱永超 on 2017/3/23.
//  Copyright © 2017年 zyc. All rights reserved.
//

#import "HomeCollectionView.h"
#import <Masonry.h>
@implementation HomeCollectionView
-(instancetype)initWithFrame:(CGRect)frame
{
    if ([super initWithFrame:frame]) {
        [self addSubview:self.homeCollectV];
        [self addSubview:self.headLabel];
        [self addSubview:self.foodLabel];
        
        // 创建一个富文本
        NSMutableAttributedString *attri = [[NSMutableAttributedString alloc] initWithString:@"最热品牌   "];
        NSMutableAttributedString *attriFoot = [[NSMutableAttributedString alloc] initWithString:@"精选商铺   "];
        // 添加表情
        NSTextAttachment *attch = [[NSTextAttachment alloc] init];
        // 表情图片
        attch.image = [UIImage imageNamed:@"4-Like-30"];
        // 设置图片大小
        attch.bounds = CGRectMake(0, 0, 20, 20);
        // 创建带有图片的富文本
        NSAttributedString *string = [NSAttributedString attributedStringWithAttachment:attch];
        [attri appendAttributedString:string];
        [attriFoot appendAttributedString:string];
        // 用label的attributedText属性来使用富文本
        self.headLabel.attributedText = attri;
        self.foodLabel.attributedText = attriFoot;
        
        [self.headLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.mas_top).with.offset(20);
            make.centerX.mas_equalTo(self);
            make.height.mas_equalTo(20);
        }];
        [self.foodLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.mas_equalTo(self);
            make.height.mas_equalTo(20);
            make.top.mas_equalTo(self.homeCollectV.mas_bottom).with.offset(20);
        }];

        
    }
    return self;
}
-(UICollectionViewFlowLayout *)homeFlowLayout
{
    if (!_homeFlowLayout) {
        _homeFlowLayout = [[UICollectionViewFlowLayout alloc] init];
        _homeFlowLayout.sectionInset = UIEdgeInsetsMake(0, 10, 0, 10);
        _homeFlowLayout.itemSize = CGSizeMake(([UIScreen mainScreen].bounds.size.width-_homeFlowLayout.sectionInset.left*3)/3,self.frame.size.height-120);
        _homeFlowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    }
    return _homeFlowLayout;
}
-(UICollectionView *)homeCollectV
{
    if (!_homeCollectV) {
        _homeCollectV = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 60, self.frame.size.width, self.frame.size.height-120) collectionViewLayout:self.homeFlowLayout];
        _homeCollectV.pagingEnabled = NO;
        _homeCollectV.showsHorizontalScrollIndicator = NO;
        _homeCollectV.backgroundColor = [UIColor whiteColor];
    }
    return _homeCollectV;
}
-(UILabel *)headLabel
{
    if (!_headLabel) {
        _headLabel = [[UILabel alloc] init];
    }
    return _headLabel;
}
-(UILabel *)foodLabel
{
    if (!_foodLabel) {
        _foodLabel = [[UILabel alloc] init];
    }
    return _foodLabel;
}

@end
